import { login, getUserInfoApi } from '@/api/user'
// import { setToken, getToken } from '@/utils/auth'
const state = {
  token: '',
  userInfo: {},
  abc: '123'
}
const mutations = {
  storeSetToken (state, payload) {
    state.token = payload
  },
  storeDelToken (state) {
    state.token = ''
  },
  setUserInfo (state, userInfo) {
    state.userInfo = userInfo
  },
  removeUserInfo (state) {
    state.userInfo = {}
  }
}
const actions = {
  async storeLogin (context, payload) {
    try {
      // console.log(11111)
      const data = await login(payload)
      console.log(data)
      context.commit('storeSetToken', data)
      // setToken(data)
    } catch (error) {
      console.log(error)
    }
  },
  async getUserInfoApi (context) {
    const res = await getUserInfoApi()
    console.log(res)
    context.commit('setUserInfo', res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
